package com.beiing.tianshuai.tianshuai.mine.ui;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.beiing.tianshuai.tianshuai.R;
import com.beiing.tianshuai.tianshuai.base.BaseActivity;
import com.beiing.tianshuai.tianshuai.huodong.adapter.MyPagerAdapter;
import com.beiing.tianshuai.tianshuai.mine.ui.fragment.PersonalPublishInterestFragment;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

import butterknife.BindView;

public class PersonalPublishActivity extends BaseActivity {

    @BindView(R.id.toolbar_btn_back)
    ImageButton mToolbarBtnBack;
    @BindView(R.id.toolbar_title)
    TextView mToolbarTitle;
    @BindView(R.id.toolbar_btn_count)
    ImageButton mToolbarBtnCount;
    @BindView(R.id.toolbar_btn_information)
    ImageButton mToolbarBtnInformation;
    @BindView(R.id.sliding_tab)
    SlidingTabLayout mSlidingTab;
    @BindView(R.id.vp_fragment_container)
    ViewPager mVpFragmentContainer;

    /**
     * tabLayout的标题
     */
    private String [] mTabTitles = {"兴趣", "发现", "活动"};

    /**
     * 关联viewPager的fragments
     */
    private ArrayList<Fragment> mFragments = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.activity_personal_publish;
    }

    @Override
    protected void init() {

        Intent intent = getIntent();
        String uid = intent.getStringExtra("uid");

        mFragments.add(PersonalPublishInterestFragment.newInstance(uid, 0));
        mFragments.add(PersonalPublishInterestFragment.newInstance(uid, 2));
        mFragments.add(PersonalPublishInterestFragment.newInstance(uid, 1));

        MyPagerAdapter pagerAdapter = new MyPagerAdapter(getSupportFragmentManager(), mFragments, mTabTitles);
        mVpFragmentContainer.setAdapter(pagerAdapter);
        mSlidingTab.setViewPager(mVpFragmentContainer);

        initListener();
    }

    /**
     * 初始化监听事件
     */
    private void initListener() {
        // 返回
        mToolbarBtnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}